export function onCollection(id) {
  const favs = getCollection();
  if (favs.indexOf(id) === -1) {
    favs.push(id);
  }
  localStorage.setItem("favs", JSON.stringify(favs));
}

export function cancelCollection(id) {
  const favs = getCollection();
  //   const oneIndex = favs.findIndex((item) => item.id == id);
  const oneIndex = favs.indexOf(id);
  if (oneIndex > -1) {
    favs.splice(oneIndex, 1);
  }
  localStorage.setItem("favs", JSON.stringify(favs));
}

export function getCollection() {
  let result = [];
  try {
    if (localStorage.getItem("favs")) {
      result = JSON.parse(localStorage.getItem("favs"));
    }
  } catch (err) {
    console.log(err);
  }
  return result;
}
